BUILD_DIR = build
MAIN_TEX = svnversion.tex
REVISION_TEX = revision.tex
TEX = $(MAIN_TEX) $(REVISION_TEX)
PDF = $(BUILD_DIR)/svnversion.pdf

MKDIR = mkdir
RM = rm
SED = sed
SED_COMMAND = "s/\([0-9]\+:\)\?\([0-9]\+[A-Z]*\)/\2/"
REVISION_BAT = revision.bat
SVNVERSION = svnversion
SVNVERSION_OPTIONS = -n
LATEX = pdflatex
LATEX_OPTIONS = -output-directory=$(BUILD_DIR)

WC_VERSION = $(shell $(SVNVERSION) $(SVNVERSION_OPTIONS) . | $(SED) $(SED_COMMAND))

all: rev $(PDF)

rev:
	$(REVISION_BAT) $(WC_VERSION) $(REVISION_TEX)

$(PDF) : $(TEX)
	if not exist $(BUILD_DIR) $(MKDIR) $(BUILD_DIR)
	$(LATEX) $(LATEX_OPTIONS) $(MAIN_TEX)

clean:
	$(RM) -rf $(BUILD_DIR)